<%--                                                                       --%>
<%-- Copyright (c) 2001-2004 BroadVision, Inc.  All rights reserved.       --%>
<%--                                                                       --%>
<%-- This software is copyrighted. Under the copyright laws, this software --%>
<%-- may not be copied, in whole or in part, without prior written consent --%>
<%-- of BroadVision, Inc. or its assignees. This software is provided      --%>
<%-- under the terms of a license between BroadVision and the recipient,   --%>
<%-- and its use is subject to the terms of that license.                  --%>
<%--                                                                       --%>
<%-- This software may be protected by one or more U.S. and International  --%>
<%-- patents.  Certain applications of BroadVision One-To-One software are --%>
<%-- covered by U.S. patent 5,710,887.                                     --%>
<%--                                                                       --%>
<%-- TRADEMARKS: BroadVision and BroadVision One-To-One are registered     --%>
<%-- trademarks of BroadVision, Inc., in the United States and the         --%>
<%-- European Community, and are trademarks of BroadVision, Inc., in other --%>
<%-- countries.  The BroadVision logo, is a trademark of BroadVision,      --%>
<%-- Inc., in the United States and other countries.                       --%>
<%--                                                                       --%>

<%@ page language="java" %>

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/bv-html.tld" prefix="bvhtml" %>

<script language="javascript">
function onClickCancel(theForm) {
  if (confirm('<bean:message key="cs.confirm.cancel.edit.phase"/>')) {
    theForm.action = '<html:rewrite page="/cs/phaseList.do"/>';
    theForm.submit();
  } else {
    return false;
  }
}

function onClickSave(theForm) {
  if (validateForm(theForm)) {
    theForm.submit();
  }
  else {
    return false;
  }
}

function confirmDeletePhase(theForm) {
  if (confirm('<bean:message key="cs.confirm.delete.phase"/>')) {
    theForm.submit();
  } else {
    return false;
  }
}


//
// Trims leading blanks.
//
function stringLeftTrim(s)
{
   return s.replace(/^ +/, "");
}

//
// Trims trailing blanks.
//
function stringRightTrim(s)
{
   return s.replace(/ +$/, "");
}

//
// Trims leading and trailing blanks.
//
function stringTrim(s)
{
   return stringRightTrim(stringLeftTrim(s));
}

//
// Validate the user's entries.
//
function validateForm(theForm) 
{
   var phaseName = stringTrim(theForm.name.value);

   if (phaseName == "") 
   {
      alert("<bean:message key="cs.error.phase.name"/>");
      return false;
   }

   var phaseDesc = stringTrim(theForm.description.value);
   if (phaseDesc.length >= 2000) 
   {
      alert("<bean:message key="cs.error.description"/>");
      return false;
   }

   var phaseGoal = stringTrim(theForm.goal.value);
   if (phaseGoal.length >= 2000) 
   {
      alert("<bean:message key="cs.error.phase.goal"/>");
      return false;
   }

   theForm.name.value = phaseName;
   return true;
}


// -->
</script>

<!-- Zone 5 starts here.  -->
<table class="zoneFive" width="100%" border="0" cellspacing="0" cellpadding="0" 
       summary="content area">
  <tr>
    <td valign="top">
    
    <!--start microsite logo and name here-->
    <div class="pageTitle">
      <%@ include file="/cs/microsite/micrositeNaviInfo.jsp" %>
    </div> 
    <!--end microsite logo and name here-->

    <!--start title bar here-->
    <div class="pageSubtitle">
      <%-- If the phaseId == 0, this is a "Create New Phase" page, --%>
      <%-- Otherwise, this is an "Edit" phase page.  --%>
      <span class="left">
        <%-- titleName is prepared in the PhaseEditAction or PhaseNewAction. --%>
        <bean:write name="phaseEditView" property="pageTitle"/>
      </span>
        <%-- Show Delete button if this is in edit phase page 
             and it is not editing the current phase of the microsite. --%>       
      <logic:notEqual name="csPhaseEditForm" property="phaseId" value="0">
        <logic:equal name="csPhaseEditForm" property="equalToCurrentPhase" value="false">

          <span class="right">
            <!-- delete phase button -->        
            <html:form action="/cs/phaseDelete.do">
              <bvhtml:hiddenList name="micrositeNaviInfoView" property="urlParams" scope="request"/>

              <html:button styleClass="titleButton" property="deletePhaseBtn" 
                titleKey="button.delete" onclick="confirmDeletePhase(this.form)">
                <bean:message key="button.delete"/>
              </html:button>
            </html:form>
          </span>

        </logic:equal>
      </logic:notEqual>
    </div> 
    <!--end title bar here-->      
  
    <div class="blockWrap">
    
    <%-- When it is creating new phase, 
         show instruction for current phase indicator. --%>

    <logic:equal name="csPhaseEditForm" property="phaseId" value="0">
    <div class="pageInstructions">
      <bean:message key="cs.phase.currentphase.note" />
    </div>
    </logic:equal>
    <!-- start Page Instructions -->
    <div class="pageInstructions">
      <logic:equal name="csPhaseEditForm" property="phaseId" value="0">
        <bean:message key="cs.phase.new.note"/>
      </logic:equal>
      <logic:notEqual name="csPhaseEditForm" property="phaseId" value="0">
        <bean:message key="cs.phase.edit.note"/>      
      </logic:notEqual>     
    </div>
    <!-- End Page Instructions -->
   
    <!--start main content area here-->
    <html:form action="/cs/phaseSave.do" onsubmit="return false;">
    
    <html:hidden name="phaseEditView" property="reorderable" />
    <%-- include hidden fields for url params. --%>
    <bvhtml:hiddenList name="micrositeNaviInfoView" property="urlParams" scope="request"/>
    
    <table class="labelForm" width="100%" border="0" cellspacing="0" 
           cellpadding="0" summary="Phase Information">    
      <!-- name -->
      <tr>
        <td nowrap width="20%" class="label"><bean:message key="cs.name"/>*: </td>
        <td width="80%" nowrap class="labelField"> 
          <html:text property="name" size="31" maxlength="80"/>
        </td>
      </tr>
      <!-- description -->
      <tr> 
        <td nowrap width="20%" class="label"> 
          <bean:message key="cs.description"/>: 
        </td>
        <td width="80%" nowrap class="labelField" valign="top"> 
          <html:textarea property="description" cols="45" rows="4"/>
        </td>
      </tr>
      <!-- goal -->
      <tr> 
        <td nowrap width="20%" class="label" valign="top"><bean:message key="cs.goal"/>:</td>
        <td width="80%" nowrap class="labelField"> 
          <html:textarea property="goal" cols="45" rows="4"/>
        </td>
      </tr>

      <%-- show list of phases with radio buttons for create/edit phase.--%> 
      
      <logic:equal name="phaseEditView" property="reorderable" value="true">
      
      <tr> 
        <td nowrap width="20%" class="label" valign="top">
          <bean:message key="cs.phase.new.setphase.before"/>:
        </td>
        <td width="80%" nowrap class="labelField">
          <logic:iterate id="phase" name="phaseEditView" property="phaseNamesAndIds">
            <html:radio idName="phase" property="insertBeforePhaseId" value="value"/>
            <bean:write name="phase" property="label" /><br><br>
          </logic:iterate>
          <html:radio name="csPhaseEditForm" property="insertBeforePhaseId" value="-9999" />
          <bean:message key="cs.phase.new.addtolast" /><br><br>
        </td>
      </tr>
      </logic:equal>
    </table>
    <!--end main content area here-->

    <!--start reset, cancel, save buttons bar area here-->
    <div class="pageButtonWrap" align="right">
      <!-- reset button -->
      <html:reset styleClass="pageButton" property="resetBtn" titleKey="button.reset">
        <bean:message key="button.reset"/>
      </html:reset>
      &nbsp;&nbsp;
      <!-- cancel button -->
      <html:button styleClass="pageButton" property="cancelBtn" 
                   titleKey="button.cancel" onclick="onClickCancel(this.form)">
        <bean:message key="button.cancel"/>
      </html:button>
      <!-- save button -->
      <html:button styleClass="pageButton" property="saveBtn" 
            titleKey="button.save" onclick="onClickSave(this.form)">
        <bean:message key="button.save"/>
      </html:button>
    </div>
    <!--end reset, cancel, save buttons bar area here-->

    </html:form>
    
    </div>
    </td>
  </tr>
</table>
<!--end zone 5 content here --> 

